package Lab4;

import Lab1.GCD;
import Lab1.ExpMod;
import Lab2.RSA;

import java.util.ArrayList;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * User: boo
 * Date: 22.10.13
 * Time: 9:43
 * To change this template use File | Settings | File Templates.
 */
public class PokerTestV2 {
    // ♠  Spades; ♥  Hearts;  ♣  Clubs; ♦  Diamonds;
    static String[] koloda = {"2♠","2♥","2♣","2♦",  "3♠","3♥","3♣","3♦",  "4♠","4♥","4♣","4♦" ,  "5♠","5♥","5♣","5♦",
            "6♠","6♥","6♣","6♦",  "7♠","7♥","7♣","7♦",  "8♠","8♥","8♣","8♦",   "9♠","9♥","9♣","9♦",
            "10♠","10♥","10♣","10♦",   "Jack♠","Jack♥","Jack♣","Jack♦",  "Queen♠","Queen♥","Queen♣","Queen♦",
            "King♠","King♥","King♣","King♦",  "Ace♠","Ace♥","Ace♣","Ace♦"};
    static ArrayList<Integer> intArr = new ArrayList<Integer>();
    static int playerNum = Integer.parseInt( MainFrame.playerNum);

    static class Randomize extends Random {
        public int myNextInt (int border){
            int next=0;
            intArr.add(nextInt(border));
            next=nextInt(border);
            for (int i=0;i<intArr.size();i++)
                do{
                    for (int j=0;j<intArr.size();j++){
                        if (next==intArr.get(j))
                            next=nextInt(border);
                    }
                }while (next==intArr.get(i));
            intArr.add(next);
            return (next);}
    }

    public int[] initValue(int P){
        //каждому игроку генерируем пару Ca Da;
        RSA Value = new RSA();
        int Ca=0;
        do{
            Ca=Value.Q;
        }while(! (GCD.gcd((P - 1), Ca)[0]==1));
        int Da = (GCD.gcd(Ca,(P-1))[1]+(P-1)%(P-1));

        int[] CaDa = new int[2];
        CaDa[0]=Ca;
        CaDa[1]=Da;
    return (CaDa);}

     class User {
            RSA Value = new RSA();
            int P=Value.P;
              int Ca = initValue(P)[0];
              int Da = initValue(P)[1];
    }

    public long[] randomNum( int P){
        //поставили каждой карте в соответствие случайное число
        long[] digitKoloda = new long[52];
        Randomize boo = new Randomize();
        for (int i=0;i<52;i++)
            digitKoloda[i]= boo.myNextInt(P-2)+1;
    return (digitKoloda);}

    public long[] codeCard (long[] digitKoloda, int Ca,int P){
        //кодируем колоду
              long[] codedKoloda = new long[digitKoloda.length];
        for (int i=0;i<codedKoloda.length;i++)
            codedKoloda[i]= ExpMod.FastExpMod(digitKoloda[i],Ca,P) ;
    return (codedKoloda);
    }

    static long[] selectCards(long[] digitKoloda){
        //игрок случайно выбирает две карты
      long[] TwoCards = new long[2];
        Randomize boo = new Randomize();
        for (int i=0;i<2;i++)
             TwoCards[i]=digitKoloda[boo.myNextInt(digitKoloda.length)];
    return (TwoCards);}


    static long[] deleteSelectedCards( long[] digitKoloda, long FirstCard, long SecondCard ){
        //удаляем уже выбранные карты из колоды
     ArrayList<Long> temp = new ArrayList<Long>();
        for (int i=0;i<digitKoloda.length;i++)
            temp.add(digitKoloda[i]);
        temp.remove(FirstCard);
        temp.remove(SecondCard);
     long[] newDigitKoloda=new long[temp.size()];
        for (int i=0;i<temp.size();i++)
            newDigitKoloda[i]=temp.get(i);
    return (newDigitKoloda);}

    public void encodeCards( long[] TwoCards, int Da, int P){
        //пускаем дешифровать выбранные карты
        long[] encodeTwoCards = new long[2];
        for (int i=0;i<encodeTwoCards.length;i++)
            encodeTwoCards[i]=ExpMod.FastExpMod(TwoCards[i],Da,P);
    }
    public void swap (long[]a,int i,int change){
        long temp = a[i];
        a[i]=a[change];
        a[change]=temp;
    }

    public void shuffleArray (long[] arr){
        int n = arr.length;
        Random random = new Random();
        random.nextInt();
        for (int i = 0; i < n-1; i++) {
            int change = i + random.nextInt(n - i);
            swap(arr, i, change);
        }
    }


    public void main (String[] args){

        RSA Value = new RSA();
        int P=Value.P;

        playerNum=2;

    }
}
